#include "StdAfx.h"
#include "BaseProvider.h"

using namespace SmartTrade;

BaseProvider::BaseProvider(void)
{
	enumStatus_ = Uninit;
	pContext_ = NULL;
}


BaseProvider::~BaseProvider(void)
{
}

void BaseProvider::SetContext(Ptr_Context pContext){
	pContext_ = pContext;
}

void BaseProvider::SetConnectInfo(const string& strAddresses,const string& strBrokerId,
	const string& strLoginId,const string& strPassword)
{
	strBrokerId_ = strBrokerId;
	strLoginId_ = strLoginId;
	strPassword_ = strPassword;
	Split(setAddresses_ , strAddresses);
}

void BaseProvider::FilterData(const Ptr_DepthMarketData pDepthMarketData){
	if(NULL == pContext_)
		return;
	pContext_->FilterData(pDepthMarketData);

}

void BaseProvider::AddSubcribedInst(const string& strProvName,const string& strInstId)
{
	set<string>::iterator found = setInstrumentId_.find(strInstId);
	if(setInstrumentId_.end() == found  )
		setInstrumentId_.insert(strInstId);

	pContext_->Subscribe(strProvName,strInstId);

}
void BaseProvider::AddSubcribedInst(const string& strProvName,const string& strInstId,const string& strExchId)
{
	AddSubcribedInst(strProvName,strInstId);
	if(mapInstrumentId_.find(strInstId) == mapInstrumentId_.end())
		mapInstrumentId_.insert(map<string,string>::value_type(strInstId,strExchId));

}
void BaseProvider::DelSubcribedInst(const string& strInstId)
{
	set<string>::iterator found = setInstrumentId_.find(strInstId);
	if(found != setInstrumentId_.end())
		setInstrumentId_.erase(found);

	map<string,string>::iterator mapFound =  mapInstrumentId_.find(strInstId);
	if (mapFound != mapInstrumentId_.end())
		mapInstrumentId_.erase(mapFound);

	pContext_->UnSubscribe(strInstId);
}



